package com.polaris.live.utils.sensor.module

import androidx.appcompat.app.AppCompatActivity
import com.polaris.live.utils.route.RouterUtils
import com.polaris.live.utils.sensor.base.DialogModule
import com.polaris.live.utils.sensor.base.FunctionModule
import com.polaris.live.utils.sensor.base.IModule
import com.polaris.live.common.util.ToastGravity
import com.lxj.xpopup.XPopup

/**
 * WebToolsModule
 *
 * @author Created by lucas on 2023/10/26 19:45
 * @since 1.0.0
 */
class WebToolsModule(
    context: AppCompatActivity
) : DialogModule(context) {

    override val title: String
        get() = "Web Tools"

    override fun createModules(): Array<IModule> = arrayOf(
        FunctionModule(mContext, "Browse Web", {
            XPopup.Builder(mContext)
                .hasStatusBarShadow(false)
                .isDestroyOnDismiss(true)
                .asInputConfirm("Browse Web", null) {
                    if (it.startsWith("http")) {
                        RouterUtils.routerWeb(it)
                    } else {
                        ToastGravity.showGravity("Please enter the correct URL")
                    }
                }
                .show()
        })
    )
}